package com.itemOrder {
	import com.greensock.TweenMax;

	import flash.display.Sprite;
	import flash.events.MouseEvent;

	public class ItemOrder extends Sprite {
		private	var _button : RadioButtonItem;
		private var _labels : Array = new Array("start", "end", "random");
		private	var	_numRadioButtons : int = _labels.length;
		private var _currentNav : Sprite;

		public function ItemOrder() {
			createRadioBtns();
		}

		private function createRadioBtns() : void {
			for (var i : int = 0 ; i < _labels .length ;i++) {
				_button = new RadioButtonItem(_labels[i]);
				_button.y = i * 20;
				addChild(_button);
				_button.addEventListener(MouseEvent.MOUSE_OVER, buttonOver);
				_button.addEventListener(MouseEvent.MOUSE_OUT, buttonOut);
				_button.addEventListener(MouseEvent.CLICK, buttonClick);
			}
		}

		private function buttonOver(e : MouseEvent) : void {
			var navItem : Sprite = e.target as Sprite;
			if (navItem != _currentNav) {
				TweenMax.to(e.target, .5, {tint:0x787879});
			}
		}

		private function buttonOut(e : MouseEvent) : void {
			var navItem : Sprite = e.target as Sprite;
			if (navItem != _currentNav) {
				TweenMax.to(e.target, .2, {tint:null});
			}
		}

		private function buttonClick(e : MouseEvent) : void {
			var navItem : Sprite = e.target as Sprite;
			if (_currentNav != null) {
				TweenMax.to(_currentNav, .3, {tint:null});
			}
			TweenMax.to(e.target, .3, {tint:0x000000});
			_currentNav = navItem;
		}
	}
}
